

/*
regressions of auction shocks on various measures of asset prices at auctions
interacted with crisis indicator and separated by maturity

output:
- t3e_*.tex: various asset regressions; combined with python

*/


* plotting options
set scheme lean_uncluttered


********************************************************************************
********************************************************************************
n di "intraday regressions, interacted with crisis"

use ../data/phreg_clean_auction_notesbonds_govpx_shock_all.dta, clear

* create D_star options
local tau_star 3
local star_window 2

tempvar _shock_mean
bys auction_id: egen `_shock_mean' = mean(D_shock) ///
	if maturity_remaining>=`=(`tau_star' - 0.5*`star_window')' & ///
		maturity_remaining<=`=(`tau_star' + 0.5*`star_window')'
bys auction_id: egen D_star = mean(`_shock_mean')
drop `_shock_mean'

* drop additional yield data
* just need D_star; one obs per auction
bys cusip auctionDate (maturity_remaining): keep if _n==1

* shock interactions
gen D_star_S0 = D_star*(term_long==0)*(high_ra==0)
gen D_star_S1 = D_star*(term_long==0)*(high_ra==1)
gen D_star_L0 = D_star*(term_long==1)*(high_ra==0)
gen D_star_L1 = D_star*(term_long==1)*(high_ra==1)


* label data
label var D_star " \$ D_t^{(\tau^*)} \$ "
label define long_var_vals 0 "Short" 1 "Long"
label define ra_var_cals 0 "Non-Crisis" 1 "Crisis"
label values term_long long_var_vals
label values high_ra ra_var_cals



rename auctionDate date
rename cusip auction_cusip
* intraday etfs
merge 1:1 date auction_cusip using ../data/input/taq_shock.dta, nogen keep(match)

* for newey-west SEs
sort release_time
gen _T = _n
tsset _T
gen year = year(date)



* rescale shocks to log points, and create label
local taq_long_ra BSV BIV BLV CSJ CIU CLY
local taq_ra_only LQD HYG MBB VMBS SPY IWM

foreach tic in `taq_long_ra' `taq_ra_only' {
	replace D_shock`tic' = 100*D_shock`tic'
	label var D_shock`tic' "`tic'"
}


* regressions: interact with both term_long/high_ra
eststo clear
foreach tic of local taq_long_ra {
	n di "`tic'"
	eststo r_`tic': ivreg2 D_shock`tic' c.D_star##i.term_long##i.high_ra, r bw(9)
	summ year if e(sample)
	estadd local Sample "`r(min)'-`r(max)'"
}


* options for saving tex file
local tex_tab_opts label keep(*D_star*) noomitted b(2) se(2) ///
	starlevels( * 0.10 ** 0.05 *** 0.01) nonotes substitute(\_ _) ///
    stat(N r2 Sample, labels("Obs." "$ R^{2}$" "Sample") fmt(0 2 0 ) )

esttab r_* ///
	using ../tables/t3e_ph_regression_corp.tex, replace `tex_tab_opts'


* regressions: interact with only ra_var
eststo clear
foreach tic of local taq_ra_only {
	n di "`tic'"
	eststo r_`tic': ivreg2 D_shock`tic' c.D_star##i.high_ra, r bw(9)
	summ year if e(sample)
	estadd local Sample "`r(min)'-`r(max)'"
}

* options for saving tex file
local tex_tab_opts label keep(*D_star*) noomitted b(2) se(2) ///
	starlevels( * 0.10 ** 0.05 *** 0.01) nonotes substitute(\_ _) ///
    stat(N r2 Sample, labels("Obs." "$ R^{2}$" "Sample") fmt(0 2 0 ) )

esttab r_* ///
	using ../tables/t3e_ph_regression_misc.tex, replace `tex_tab_opts'





